package com.learning.spring.ioc.bean.jbased;

import lombok.Setter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.annotation.ImportResource;

/**
 * ClassName: AppConfig
 * Description:
 * Date: 2018/8/7 10:42 【需求编号】
 *
 * @author Sam Sho
 * @version V1.0.0
 */
@Configuration
@Import(AppInjectionConfig.class)
@ImportResource("classpath:bean-java-config.xml")
public class AppConfig {

    @Autowired
    private AppInjectionConfig appInjectionConfig;

    /**
     * Bean 的类型为返回值类型
     * Bean 的名字默认为方法名，可以通过 name 属性定义
     *
     * @return
     */
    @Bean
    public ConfigBean configBean() {
        ConfigBean configBean = new ConfigBean();
        // Spring 会被Bean 标注的方法进行aop增强
        // 调用 configInjectionBean() 不是简单的运行方法的逻辑，而是从容器中获取 Bean
        configBean.setConfigInjectionBean(appInjectionConfig.configInjectionBean());
        return configBean;
    }

}


@Setter
class ConfigBean {

    private ConfigInjectionBean configInjectionBean;

    public void done() {
        System.out.println("调用了 ConfigBean.done 方法");
    }

    public void injection() {
        System.out.println("调用了 ConfigBean.injection 方法");
        configInjectionBean.injection();
    }
}



